package controller

import (
	"golang.org/x/net/context"
	"lot_admin_api/api"
	"lot_admin_api/internal/model"
	"lot_admin_api/internal/service"
)

var Notice = cNotice{}

type cNotice struct{}

// AddNotice  添加通知
func (h *cNotice) AddNotice(ctx context.Context, req *api.AddNoticeReq) (res *model.NoticeIdRes, err error) {
	// 获取解析token得到用户信息
	id, err := service.Notice().AddNotice(ctx, req)
	res = &model.NoticeIdRes{
		Id: id,
	}
	return res, err
}

// UpdateNotice  更新通知
func (h *cNotice) UpdateNotice(ctx context.Context, req *api.UpdateNoticeReq) (res *model.NoticeIdRes, err error) {
	id, err := service.Notice().UpdateNotice(ctx, req)
	res = &model.NoticeIdRes{
		Id: id,
	}
	return res, err
}

// DeleteNotice  删除通知
func (h *cNotice) DeleteNotice(ctx context.Context, req *api.DeleteNoticeReq) (res *model.NoticeIdRes, err error) {
	id, err := service.Notice().DeleteNotice(ctx, req)
	res = &model.NoticeIdRes{
		Id: id,
	}
	return res, err
}

// NoticeInfo 通过id获取通知详情
func (h *cNotice) NoticeInfo(ctx context.Context, req *api.NoticeInfoReq) (res *model.NoticeIdAndInfoRes, err error) {
	res, err = service.Notice().SearchNotice(ctx, req.Id)
	return res, err
}

// NoticeList 获取通知列表
func (h *cNotice) NoticeList(ctx context.Context, req *api.NoticeListReq) (res *model.NoticeListRes, err error) {
	res, err = service.Notice().NoticeList(ctx, req)
	return res, err
}
